import { reactive } from "vue";
import type { FormRules } from "element-plus";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  menuName: [{ required: true, message: "请输入", trigger: "blur" }],
  menuUri: [{ required: true, message: "请输入", trigger: "blur" }],
  menuCode: [{ required: true, message: "请输入", trigger: "blur" }],
  parentId: [{ required: true, message: "请选择", trigger: "blur" }],
  sort: [
    {
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("请输入"));
        } else if (isNaN(value)) {
          callback(new Error("请输入数字"));
        } else if (Number(value) < 1) {
          callback(new Error("需大于0"));
        } else {
          callback();
        }
      },
      trigger: "blur",
      required: true
      // trigger: "click" // 如果想在点击确定按钮时触发这个校验，trigger 设置成 click 即可
    }
  ]
});
